git » fp-git.git » commit b3042e0

released 1.2. Some TODOs done.

author ecalot
2006-06-07 13:02:30 UTC
committer ecalot
2006-06-07 13:02:30 UTC
parent 13283387ca9e0fdaf4b351f730cd824dfcefa90d

released 1.2. Some TODOs done.

PR/doc/changelog.txt +10 -10
PR/src/Makefile +10 -10
PR/src/include/binary.h +1 -0
PR/src/include/common.h +1 -1
PR/src/include/compress.h +3 -1
PR/src/include/memory.h +1 -0
PR/src/lib/compression/rle_decompress.c +2 -2
PR/src/lib/compression/rlev_decompress.c +3 -3
PR/src/lib/layers/memory.c +4 -0
PR/src/lib/object/image/image16.c +9 -9
PR/src/lib/object/image/image2.c +1 -1
PR/src/lib/object/image/image256.c +8 -8
PR/src/lib/object/image/image_common.c +9 -9
PR/src/lib/object/other/binary.c +2 -1

diff --git a/PR/doc/changelog.txt b/PR/doc/changelog.txt
index 6974b6a..115d9dd 100644
--- a/PR/doc/changelog.txt
+++ b/PR/doc/changelog.txt
@@ -157,10 +157,10 @@ Versions:
   - Rewritten resource handling using dynamic structures
   - Support of partial list folder selection wildcards (e.g.
     vdungeon.dat@vdungeon/chopper/*.bmp) '*' and '?' using '&' as escape
- * PR v1.2 (scheduled 2006-03-22)
+ * PR v1.2 (2006-06-06)
   - Added 8 bits palette support
   - Added defines for positive return values in XML
-  + Added experimental POP2 RLEC decompression algorithm
+  + Added experimental POP2 RLEV decompression algorithm
   - Added --format option for unknown filename generation format
   + Added resource physical order and support of non-unique resource IDs
   - Added parsing feature @400:shape#!second
@@ -179,29 +179,29 @@ Versions:
   - Raw importation now works for pop2
   - Restructured the repository and source to support an object layer
   - When extracting, generated unknown.xml's are now all merged into one
- * PR v1.3 (scheduled 2006-04-22)
-  X Add a fatal error check when importing from a different palette size and a
+ * PR v1.3 (scheduled 2006-07-08)
+  x Add a fatal error check when importing from a different palette size and a
     warning when importing from an incorrect palette.
-  x Added full POP2 RLEC decompression algorithm
-  x Add the pop2 4-bits palette object
+  x Added full POP2 RLEV decompression algorithm
+  x Add the POP2 4-bits palette object
   x Check for memory leak
   x Clean the source
   x Common factor in LGZ compression (a .h) for win size, etc.
   x Common palette calculation
   x Create a new isDirSep in disk.h and handle all the / and \ as the same char
-  x Don't create empry unknown.xml
+  x Don't create empty unknown.xml
   x Fix ./pr -ie it -f bug
   x Fix repeated resource name in CPALACE.DAT bug
   x Fork compress to code images as a new object in a separated file
   x Move tResource* from reslist to types.h
-  x Rename "uncompress" to "decomporess"
-  x Replaced .bmp by .png files.
+  - Rename "uncompress" to "decomporess"
   x Transform flags from the hex form to the [a-y]* form (a is 1, b is 2, c is 4...)
  * PR v1.4 (future plans)
-  x Added full POP2 RLEC compression algorithm
+  x Added full POP2 RLEV compression algorithm
   x Code a palette adapting feature
   x Finish python interface
   x Fix buffer overflows (in entered filename sizes)
+  x Replace .bmp by .png files.
  * PR v1.5 (future plans)
   x Tested and make very stable
   x Source cleaned
diff --git a/PR/src/Makefile b/PR/src/Makefile
index 579c96a..7ee2148 100644
--- a/PR/src/Makefile
+++ b/PR/src/Makefile
@@ -54,7 +54,7 @@ endif
 
 ACTIONS  = .import.o .export.o .classify.o
 XML      = .parse.o .search.o .unknown.o .translate.o .tree.o
-COMPRESS = .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o .rlec_uncompress.o 
+COMPRESS = .lzg_compress.o .lzg_decompress.o .rle_compress.o .rle_decompress.o .rlev_decompress.o 
 LAYERS   = .dat.o .memory.o .list.o .reslist.o .pallist.o .disk.o .idlist.o .autodetect.o .stringformat.o .resourcematch.o .auxiliary.o
 FORMAT   = .bmp.o .mid.o .pal.o .wav.o .plv.o
 OBJECT   = .object.o .pop2_256c.o .pop1_4bit.o .image2.o .image16.o .image256.o .binary.o .sounds.o .level.o
@@ -191,17 +191,17 @@ $(XMLFILE): xml/resources.xml
 	$(INFO) Compiling RLE compression module...
 	$(CC) $(OPTIONS) -c lib/compression/rle_compress.c -o $@
 
-.lzg_uncompress.o: lib/compression/lzg_uncompress.c include/compress.h
-	$(INFO) Compiling LZG uncompression module...
-	$(CC) $(OPTIONS) -c lib/compression/lzg_uncompress.c -o $@
+.lzg_decompress.o: lib/compression/lzg_decompress.c include/compress.h
+	$(INFO) Compiling LZG decompression module...
+	$(CC) $(OPTIONS) -c lib/compression/lzg_decompress.c -o $@
 
-.rle_uncompress.o: lib/compression/rle_uncompress.c include/compress.h
-	$(INFO) Compiling RLE uncompression module...
-	$(CC) $(OPTIONS) -c lib/compression/rle_uncompress.c -o $@
+.rle_decompress.o: lib/compression/rle_decompress.c include/compress.h
+	$(INFO) Compiling RLE decompression module...
+	$(CC) $(OPTIONS) -c lib/compression/rle_decompress.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 $@
+.rlev_decompress.o: lib/compression/rlev_decompress.c include/compress.h
+	$(INFO) Compiling RLEC decompression module...
+	$(CC) $(OPTIONS) -c lib/compression/rlev_decompress.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...
diff --git a/PR/src/include/binary.h b/PR/src/include/binary.h
index e72add9..fea334e 100644
--- a/PR/src/include/binary.h
+++ b/PR/src/include/binary.h
@@ -37,6 +37,7 @@ binary.h: Princed Resources : Memory handling & comparison prototypes
 typedef struct {
 	unsigned char* data;
 	long int size;
+	int isCopy;
 }tBinary;
 
 #endif
diff --git a/PR/src/include/common.h b/PR/src/include/common.h
index a5f6383..b5beb46 100644
--- a/PR/src/include/common.h
+++ b/PR/src/include/common.h
@@ -65,7 +65,7 @@ common.h: Princed Resources : Defines and prototypes common to all PR code
 \***************************************************************/
 
 #define PR_URL                    "http://www.princed.com.ar"
-#define PR_VERSION                "v1.2-beta-BlackChar-2"
+#define PR_VERSION                "v1.3-dev1"
 #define PR_COPY                   "(c) Copyright 2003-2006 Princed Development Team"
 
 /***************************************************************\
diff --git a/PR/src/include/compress.h b/PR/src/include/compress.h
index b01127c..3ab4234 100644
--- a/PR/src/include/compress.h
+++ b/PR/src/include/compress.h
@@ -44,9 +44,11 @@ compress.h: Princed Resources : Compression headers
 
 #define COMPRESS_WORKING_ALGORITHMS 5
 
+/*
 #define COMPRESS_RESULT_FATAL   PR_RESULT_COMPRESS_RESULT_FATAL
 #define COMPRESS_RESULT_WARNING PR_RESULT_COMPRESS_RESULT_WARNING
 #define COMPRESS_RESULT_SUCCESS PR_RESULT_SUCCESS 
+*/
 
 /* Prototypes */
 
@@ -72,7 +74,7 @@ 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,
+int expandRleV(const unsigned char* input, int inputSize,
                unsigned char* output, int *outputSize);
 
 #endif
diff --git a/PR/src/include/memory.h b/PR/src/include/memory.h
index 4522aeb..cbaf778 100644
--- a/PR/src/include/memory.h
+++ b/PR/src/include/memory.h
@@ -60,5 +60,6 @@ int getOrder(const char* order);
 
 #include "binary.h"
 tBinary tbinaryallocandcopy(tBinary c);
+void freeBinary(tBinary b);
 
 #endif
diff --git a/PR/src/lib/compression/rle_decompress.c b/PR/src/lib/compression/rle_decompress.c
index d2b6395..6ce6cb2 100644
--- a/PR/src/lib/compression/rle_decompress.c
+++ b/PR/src/lib/compression/rle_decompress.c
@@ -44,7 +44,7 @@ int expandRle(const unsigned char* input, int inputSize,
 	int iCursor=0;
 
 	/* reserve memory */
-	if ((*output=malloc(40000))==NULL) return COMPRESS_RESULT_FATAL;
+	if ((*output=malloc(40000))==NULL) return PR_RESULT_COMPRESS_RESULT_FATAL;
 
 	/* main loop */
 	while (iCursor<inputSize) {
@@ -61,6 +61,6 @@ int expandRle(const unsigned char* input, int inputSize,
 	}
 
 	*outputSize=oCursor;
-	return (rep==1)?COMPRESS_RESULT_SUCCESS:COMPRESS_RESULT_WARNING;
+	return (rep==1)?PR_RESULT_SUCCESS:PR_RESULT_COMPRESS_RESULT_WARNING;
 }
 
diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c
index 47bc592..01b4cf3 100644
--- a/PR/src/lib/compression/rlev_decompress.c
+++ b/PR/src/lib/compression/rlev_decompress.c
@@ -20,7 +20,7 @@
 
 /*
 rlec_uncompress.c: Princed Resources : Image Compression Library :
-\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf  Run length encoding with checksum decompressor
+\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf  Run length encoding variant for POP2
 
  Copyright 2003, 2004, 2005, 2006 Princed Development Team
   Created: 24 Aug 2003
@@ -38,7 +38,7 @@ rlec_uncompress.c: Princed Resources : Image Compression Library :
 #include "compress.h"
 
 /* Expands RLE algorithm */
-int expandRleC(const unsigned char* input, int inputSize,
+int expandRleV(const unsigned char* input, int inputSize,
                unsigned char* output, int *outputSize) {
 	register unsigned char rep=0;
 	int oCursor=0;
@@ -63,6 +63,6 @@ int expandRleC(const unsigned char* input, int inputSize,
 	}
 	
 	*outputSize=oCursor;
-	return (rep==255)?COMPRESS_RESULT_SUCCESS:COMPRESS_RESULT_WARNING;
+	return (rep==255)?PR_RESULT_SUCCESS:PR_RESULT_COMPRESS_RESULT_WARNING;
 }
 
diff --git a/PR/src/lib/layers/memory.c b/PR/src/lib/layers/memory.c
index 2e0cc9d..10e457c 100644
--- a/PR/src/lib/layers/memory.c
+++ b/PR/src/lib/layers/memory.c
@@ -59,6 +59,7 @@ tBinary tbinaryallocandcopy(tBinary c) {
 
 	aux.data=(unsigned char*)malloc(c.size);
 	aux.size=c.size;
+	aux.isCopy=0;
 	
 	if (aux.data) memcpy(aux.data,c.data,c.size);
 	return aux;
@@ -122,3 +123,6 @@ int getOrder(const char* order) {
 	}
 }
 
+void freeBinary(tBinary b) {
+	if (!b.isCopy && b.data) free(b.data);
+}
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index 0e836af..598d0be 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -164,7 +164,7 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 	image->width =array2short(data);
 	data+=2;
 
-	if (*(data++)>1) return COMPRESS_RESULT_FATAL; /* Verify format */
+	if (*(data++)>1) return PR_RESULT_COMPRESS_RESULT_FATAL; /* Verify format */
 	image->type=(unsigned char)(*(data++));
 	dataSizeInBytes-=6;
 	switch (((image->type>>4)&7)+1) {
@@ -178,20 +178,20 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 		image->widthInBytes=(image->width+7)/8;
 		break;
 	default:
-		return COMPRESS_RESULT_FATAL;
+		return PR_RESULT_COMPRESS_RESULT_FATAL;
 	}
 
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
-	return COMPRESS_RESULT_FATAL
-#define checkResult if (result==COMPRESS_RESULT_FATAL)\
-	return COMPRESS_RESULT_FATAL
+	return PR_RESULT_COMPRESS_RESULT_FATAL
+#define checkResult if (result==PR_RESULT_COMPRESS_RESULT_FATAL)\
+	return PR_RESULT_COMPRESS_RESULT_FATAL
 
 	switch (getAlgor(image->type)) {
 		case COMPRESS_RAW: /* No Compression Algorithm */
-			if ((image->pix=getMemory(dataSizeInBytes))==NULL) return COMPRESS_RESULT_FATAL;
+			if ((image->pix=getMemory(dataSizeInBytes))==NULL) return PR_RESULT_COMPRESS_RESULT_FATAL;
 			memcpy(image->pix,data,dataSizeInBytes);
 			imageSizeInBytes=image->widthInBytes*image->height;
-			result=COMPRESS_RESULT_SUCCESS;
+			result=PR_RESULT_SUCCESS;
 			break;
 		case COMPRESS_RLE_LR: /* RLE Left to Right Compression Algorithm */
 			result=expandRle(data,dataSizeInBytes,&(image->pix),&imageSizeInBytes);
@@ -214,7 +214,7 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 			cmp_transposeImage(image,imageSizeInBytes);
 			break;
 		default:
-			result=COMPRESS_RESULT_FATAL; /* unknown algorithm */
+			result=PR_RESULT_COMPRESS_RESULT_FATAL; /* unknown algorithm */
 			break;
 	}
 	return result; /* Ok */
@@ -369,7 +369,7 @@ void* objImage16Create(tBinary cont, tObject palette, int *error) { /* use get l
 	*error=mExpandGraphic(cont.data,image,cont.size); /* TODO: pass tBinary */
 /*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
 		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
-	if (*error==COMPRESS_RESULT_FATAL) {
+	if (*error==PR_RESULT_COMPRESS_RESULT_FATAL) {
 		free(image);
 		return NULL;
 	}
diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c
index 3d9c8ca..9d324ed 100644
--- a/PR/src/lib/object/image/image2.c
+++ b/PR/src/lib/object/image/image2.c
@@ -118,7 +118,7 @@ void* objImage2Create(tBinary cont, int *error) { /* use get like main.c */
 	*error=mExpandGraphic(cont.data,image,cont.size); /* TODO: pass tBinary */
 /*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
 		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
-	if (*error==COMPRESS_RESULT_FATAL) {
+	if (*error==PR_RESULT_COMPRESS_RESULT_FATAL) {
 		free(image);
 		return NULL;
 	}
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index 829b9e2..28fb86b 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -123,7 +123,7 @@ int mExpandGraphic256(const unsigned char* data,tImage *image, int dataSizeInByt
 	image->width =array2short(data);
 	data+=2;
 
-	if (*(data++)>1) return COMPRESS_RESULT_FATAL; /* Verify format */
+	if (*(data++)>1) return PR_RESULT_COMPRESS_RESULT_FATAL; /* Verify format */
 	image->type=(unsigned char)(*(data++));
 	dataSizeInBytes-=6;
 	switch (((image->type>>4)&7)+1) {
@@ -137,7 +137,7 @@ int mExpandGraphic256(const unsigned char* data,tImage *image, int dataSizeInByt
 		image->widthInBytes=(image->width+7)/8;
 		break;
 	default:
-		return COMPRESS_RESULT_FATAL;
+		return PR_RESULT_COMPRESS_RESULT_FATAL;
 	}
 
 	/* special format has a special function */
@@ -231,9 +231,9 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 		lineI+=2;
 		if (aux>tempOutputSize) {
 			/*printf(" error: aux=%d tempOutputSize=%d\n",aux,tempOutputSize);*/
-			return COMPRESS_RESULT_WARNING;
+			return PR_RESULT_COMPRESS_RESULT_WARNING;
 		}
-		aux2= expandRleC(lineI,aux,lineO,&lineSize);
+		aux2= expandRleV(lineI,aux,lineO,&lineSize);
 		/*if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-aux-2);*/
 		lineO+=lineSize;
 		*outputSize+=lineSize;
@@ -255,9 +255,9 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 			lineI+=2;
 			if (aux>tempOutputSize) {
 				/*printf(" error: aux=%d tempOutputSize=%d\n",aux,tempOutputSize);*/
-				return COMPRESS_RESULT_WARNING;
+				return PR_RESULT_COMPRESS_RESULT_WARNING;
 			}
-			aux2= expandRleC(lineI,aux,lineO,&lineSize);
+			aux2= expandRleV(lineI,aux,lineO,&lineSize);
 			/*if (aux2) printf(" error: rle=%d linesize=%d of %d. size=%d r=%d.\n",aux2, lineSize,verify,tempOutputSize,tempOutputSize-aux-2);*/
 			lineO+=lineSize;
 			*outputSize+=lineSize;
@@ -288,7 +288,7 @@ int pop2decompress(const unsigned char* input, int inputSize, int verify, unsign
 	printf("os=%d oscheck=%d\n",os,osCheck);
 */
 
-	return COMPRESS_RESULT_SUCCESS;
+	return PR_RESULT_SUCCESS;
 }
 
 extern FILE* outputStream;
@@ -311,7 +311,7 @@ void* objImage256Create(tBinary cont, tObject palette, int *error) { /* use get
 	*error=mExpandGraphic256(cont.data,image,cont.size); /* TODO: pass tBinary */
 /*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
 		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
-	if (*error==COMPRESS_RESULT_FATAL) {
+	if (*error==PR_RESULT_COMPRESS_RESULT_FATAL) {
 		free(image);
 		return NULL;
 	}
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index 0e836af..598d0be 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -164,7 +164,7 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 	image->width =array2short(data);
 	data+=2;
 
-	if (*(data++)>1) return COMPRESS_RESULT_FATAL; /* Verify format */
+	if (*(data++)>1) return PR_RESULT_COMPRESS_RESULT_FATAL; /* Verify format */
 	image->type=(unsigned char)(*(data++));
 	dataSizeInBytes-=6;
 	switch (((image->type>>4)&7)+1) {
@@ -178,20 +178,20 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 		image->widthInBytes=(image->width+7)/8;
 		break;
 	default:
-		return COMPRESS_RESULT_FATAL;
+		return PR_RESULT_COMPRESS_RESULT_FATAL;
 	}
 
 #define checkSize if (imageSizeInBytes!=(image->widthInBytes*image->height))\
-	return COMPRESS_RESULT_FATAL
-#define checkResult if (result==COMPRESS_RESULT_FATAL)\
-	return COMPRESS_RESULT_FATAL
+	return PR_RESULT_COMPRESS_RESULT_FATAL
+#define checkResult if (result==PR_RESULT_COMPRESS_RESULT_FATAL)\
+	return PR_RESULT_COMPRESS_RESULT_FATAL
 
 	switch (getAlgor(image->type)) {
 		case COMPRESS_RAW: /* No Compression Algorithm */
-			if ((image->pix=getMemory(dataSizeInBytes))==NULL) return COMPRESS_RESULT_FATAL;
+			if ((image->pix=getMemory(dataSizeInBytes))==NULL) return PR_RESULT_COMPRESS_RESULT_FATAL;
 			memcpy(image->pix,data,dataSizeInBytes);
 			imageSizeInBytes=image->widthInBytes*image->height;
-			result=COMPRESS_RESULT_SUCCESS;
+			result=PR_RESULT_SUCCESS;
 			break;
 		case COMPRESS_RLE_LR: /* RLE Left to Right Compression Algorithm */
 			result=expandRle(data,dataSizeInBytes,&(image->pix),&imageSizeInBytes);
@@ -214,7 +214,7 @@ int mExpandGraphic(const unsigned char* data,tImage *image, int dataSizeInBytes)
 			cmp_transposeImage(image,imageSizeInBytes);
 			break;
 		default:
-			result=COMPRESS_RESULT_FATAL; /* unknown algorithm */
+			result=PR_RESULT_COMPRESS_RESULT_FATAL; /* unknown algorithm */
 			break;
 	}
 	return result; /* Ok */
@@ -369,7 +369,7 @@ void* objImage16Create(tBinary cont, tObject palette, int *error) { /* use get l
 	*error=mExpandGraphic(cont.data,image,cont.size); /* TODO: pass tBinary */
 /*	if ((result==COMPRESS_RESULT_WARNING)&&hasFlag(verbose_flag))
 		fprintf(outputStream,PR_TEXT_EXPORT_BMP_WARN);*/
-	if (*error==COMPRESS_RESULT_FATAL) {
+	if (*error==PR_RESULT_COMPRESS_RESULT_FATAL) {
 		free(image);
 		return NULL;
 	}
diff --git a/PR/src/lib/object/other/binary.c b/PR/src/lib/object/other/binary.c
index d20f8af..20de390 100644
--- a/PR/src/lib/object/other/binary.c
+++ b/PR/src/lib/object/other/binary.c
@@ -52,6 +52,7 @@ void* objBinaryCreate(tBinary cont, int *error) { /* use get like main.c */
 	
 	r=(tBinary*)malloc(sizeof(tBinary));
 	*r=cont;
+	r->isCopy=1;
 	return (void*)r;
 }
 
@@ -66,7 +67,7 @@ void* objBinaryRead(const char* file,int *result) {
 		*result=o.size;
 		return NULL;
 	}
-	return objBinaryCreate(o,result);
+	return objBinaryCreate(o,result); /* TODO: isCopy=0 */
 }
 
 int objBinarySet(void* o,tResource* res) {